var Koa = require('koa');
var Router = require('koa-router');

var app = new Koa();
var router = new Router();

let users = {
    "1": "hello"
};
app.use(router.routes()).use(router.allowedMethods());
router.param('user', function(id, ctx, next) {
    ctx.user = users[id];
    if (!ctx.user)
        return ctx.status = 404;
    return next();
}).get('/users/:user', function(ctx) {
    ctx.body = ctx.user;
}).get('/users/:user/friends', function(ctx) {
    return ctx.user.getFriends().then(function(friends) {
        ctx.body = friends;
    });
})

app.listen(3000);
